﻿using UnityEngine;
using System.Collections;

public class Monster : MonoBehaviour {
    public Vector3 startPosition;
    
    public Vector3 targetPosition = new Vector3();
    public GameObject targetObject;
    public AnimationProgress animationProgress = null;
    public float biteSize = 2;
    void Start()
    {
        collider.enabled = false;
        startPosition = transform.position;
        if (animationProgress != null)
            animationProgress.biteDelegate += bite;
        if (animationProgress != null)
            animationProgress.destroyDelegate += destroy;
    }
    void Update()
    {
        if (animationProgress != null)
        {
            transform.position = Vector3.Lerp(startPosition, targetPosition, animationProgress.animationProgress);
        }
        
    }
    void OnDrawGizmos()
    {
        Gizmos.DrawCube(targetPosition, Vector3.one);
    }/*
    void OnTriggerEnter(Collider other)
    {
       // Debug.Log("te");
        if (other.tag == "Player")
        {
            other.SendMessage("explode");
        }
    }
      * */
    void destroy()
    {
        Destroy(gameObject);
    }
    void bite()
    {
    	AudioController.audio_controller.GetSound("MonsterGrowlClose").Play();
        if (Vector3.Distance(transform.position, targetObject.transform.position) < biteSize)
        {
            targetObject.SendMessage("explode");
        }
        collider.enabled = true;
    }
}
